<?php

class App_Methods_Request_GetMenuData {

  /**
   *
   * @var App_Methods_Data_App
   */
  public $app;

  public function __construct($params) {
    $this->app = new App_Methods_Data_App($params->app);
  }

  public function process() {
    $applications = ApplicationsQuery::create()
    ->useUserGroupApplicationsQuery()
    	->filterByUserGroupId(Core_Auth::getInstance()->getUser()->getUserGroupId())
    ->endUse()
    ->useApplicationDataSetsQuery()
    	->filterByStatus(ApplicationDataSets::STATUS_ACCEPTED)
    	->useApplicationDataDefsQuery(null, Criteria::LEFT_JOIN)
    		->leftJoinUserApplicationData()
    		->addJoinCondition('UserApplicationData', 'UserApplicationData.UserId = ?', Core_Auth::getInstance()->getUser()->getId())
    	->endUse()
    ->endUse()
    ->useUserPulpitQuery(null, Criteria::LEFT_JOIN)
    	->orderByDbOrder(Criteria::ASC)
    	->addCond('cond1', UserPulpitPeer::VISIBLE, 1, Criteria::EQUAL)
    	->addCond('cond2', UserPulpitPeer::VISIBLE, null, Criteria::ISNULL)
    	->combine(array('cond1', 'cond2'), Criteria::LOGICAL_OR)
    ->endUse()
    ->addJoinCondition('UserPulpit', 'UserPulpit.UserId = ?', Core_Auth::getInstance()->getUser()->getId())
    ->with('UserPulpit')
    ->with('ApplicationDataSets')
    ->with('ApplicationDataDefs')
    ->with('UserApplicationData')
    ->find();
  	
    return new App_Methods_Response_GetMenuData($applications);
  }

}